<?php
/**
* SocialEngine
*
* @category   Application_Extensions
* @package    Flashgame
* @version    $Id: Level.php 6072 2010 YouNet $
* @author     To Anh
*/

class Flashgame_Form_Admin_Package extends Engine_Form
{
    public function init()
    {
        $this
        ->setTitle('Create A Package');
        $this->loadDefaultDecorators();
        $this->getDecorator('Description')->setOptions(array('tag' => 'h4', 'placement' => 'PREPEND'));

        // prepare user packages
        $table = Engine_Api::_()->getDbtable('levels', 'authorization');
        $select = $table->select();
        $user_levels = $table->fetchAll($select);

        foreach ($user_levels as $user_level){
            $levels_prepared[$user_level->level_id]= $user_level->getTitle();
        }

        // Name
        $this->addElement('Text', 'package_name', array(
        'label' => 'Name',
        'allowEmpty' => false,
        'required' => true,
        'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 64)),
        ),
        'filters' => array(
        new Engine_Filter_Censor(),
        'StripTags',
        new Engine_Filter_StringLength(array('max' => '63'))
        )
        ));
        $this->addElement('Textarea', 'package_description', array(
        'label' => 'Description'
        ));

        // Enable
        $enable_array = array('0'=>"No",'1'=>"Yes");
        $this->addElement('Select', 'package_enabled', array(
        'label' => 'Enable',
        'multiOptions' => $enable_array
        ));
        /*
        // Associated Level
        $this->addElement('Select', 'package_level_id', array(
        'label' => 'Associated Level',
        'multiOptions' => $levels_prepared,
        'allowEmpty' => false,
        'required' => true,
        'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 64)),
        ),
        ));

        // Downgrade Level
        $this->addElement('Select', 'package_downgrade_level_id', array(
        'label' => 'Downgrade Level',
        'multiOptions' => $levels_prepared,
        ));
        */
        //Plan Period
        $this->addElement('Text', 'package_period', array(
        'label' => 'Plan Period',
        'validators' => array(
            array('NotEmpty', true),
            array(new Zend_Validate_Int(), true,
                'messages' => array(
                    Zend_Validate_Int::INVALID => "Please enter valid number.",
                    Zend_Validate_Int::NOT_INT => "'Please enter valid number."
                )
            )
        )
        ));
        //Periodtypes
        $periodtypes = Engine_Api::_()->flashgame()->getPeriodtypes();
        $this->addElement('Select', 'package_periodtype', array(
        'multiOptions' => $periodtypes,
        ));

        /*
        //Recurring?   
        $this->addElement('Select', 'package_recurring', array(
        'label' => 'Recurring?',
        'multiOptions' => $enable_array,

        ));

        $this->addElement('Text', 'package_recurring_cycles', array(
        'label' => ' and has ',
        'description' => 'recurring cycles ("0" for unlimited)',
        )); 
        */ 
        //Price
        $this->addElement('Text', 'package_price', array(
        'label' => 'Price',
        'allowEmpty' => false,
        'required' => true,
        'validators' => array(
            array('NotEmpty', true),
            
            array(new Zend_Validate_Float(), true,
                'messages' => array(
                    Zend_Validate_Float::INVALID => "Invalid type given, value should be a string or a number",
                    Zend_Validate_Float::NOT_FLOAT => "'%value%' does not appear to be an number"
                )
            )
            
        )
        )); 

        //Price
        /*
        $this->addElement('Text', 'package_onetime_price', array(
        'label' => 'Initial price',
        'allowEmpty' => false,
        'required' => true,
        'validators' => array(
        array('NotEmpty', true),
        array('StringLength', false, array(1, 64)),
        ),
        ));
        */ 
        $this->addElement('Button', 'submit', array(
        'label' => 'Save Package',
        'type' => 'submit',
        'decorators' => array(array('ViewScript', array(
        'viewScript' => '_formButtonCancel.tpl',
        'class'      => 'form element'
        )))));

        /*

        $this->addElement('Button', 'submit', array(
        'label' => 'Save Package',
        'type' => 'submit',
        ));
        $this->addElement('Cancel', 'cancel', array(
        'label' => 'cancel',
        'link' => true,
        'prependText' => ' or ',
        'decorators' => array(
        'ViewHelper'
        )
        ));
        $this->addDisplayGroup(array('submit', 'cancel'), 'buttons');
        $button_group = $this->getDisplayGroup('buttons');
        $button_group->addDecorator('DivDivDivWrapper');
        */
    }
}
